package com.xmg.p2p.base.service.impl;

import com.xmg.p2p.base.domain.SystemDictionary;
import com.xmg.p2p.base.mapper.SystemDictionaryMapper;
import com.xmg.p2p.base.query.PageResult;
import com.xmg.p2p.base.query.SystemDictionaryQueryObject;
import com.xmg.p2p.base.service.ISystemDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * lcd  2020/5/14
 * Description:
 */
@Service
public class SystemDictionaryServiceImpl implements ISystemDictionaryService {
    @Autowired
    private SystemDictionaryMapper systemDictionaryMapper;
    @Override
    public PageResult queryListSystemDictionary(SystemDictionaryQueryObject qo) {
        PageResult pageResult;
        int i = systemDictionaryMapper.queryForCount(qo);
        if (i > 0) {
            List<SystemDictionary> systemDictionaries = systemDictionaryMapper.queryList(qo);
            pageResult = new PageResult(systemDictionaries, i, qo.getCurrentPage(), qo.getPageSize());
        }else {
            pageResult = PageResult.empty(qo.getPageSize());
        }
        return pageResult;
    }

    @Override
    public void saveOrUpdate(SystemDictionary dictionary) {
        if (dictionary.getId() != null) {
            systemDictionaryMapper.updateByPrimaryKey(dictionary);
        }else {
            systemDictionaryMapper.insert(dictionary);
        }
    }

    @Override
    public List<SystemDictionary> findAll() {
        return systemDictionaryMapper.findAll();
    }
}
